#include<iostream>
using namespace std;
int n, a, b;
int main()
{
	cin >> n >> a >> b;
	int ans = 10001;
	for (int i = 0; i * a <= n; i++) {
		ans = min(ans, (n - i * a) % b);
	}
	cout << ans << endl;
	return 0;
}